package web;

/**
 * @author zy
 * @create 2021/12/5 14:35
 */

import entity.Client;
import entity.Supplier;
import org.apache.commons.beanutils.BeanUtils;
import service.ClientService;
import service.SupplierService;
import service.impl.ClientServiceImpl;
import service.impl.SupplierServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @author zy
 * @create 2021/12/5 14:02
 */
@WebServlet("/AddClient")
public class AddClient extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Client client = new Client();
        try {
            BeanUtils.populate(client,request.getParameterMap());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        ClientService clientService = new ClientServiceImpl();
        clientService.AddClient(client);
        response.sendRedirect(request.getContextPath() + "/ClientListServlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
